/**
 * @author Matan Mizrahi,Chen weissman
 * Introduction to computer science, assingment5
 * Date:2.1.2011
 *
 * a class that represents a constant.
 */
public class Constant implements Expression {
    //*********************************Fields************************************//
	private double value;
	
    //*********************************Constructors******************************//
/**
 * Constructs a new constant using a given number.
 * 
 * @param num the number which you want to represent.
 * @return a new object from the type Constant that its value is num.
 */
	public Constant(double num){
		this.value=num;
	}
	
    //*********************************Behavior**********************************//
    /**
     * Returns the symbol of the last operation that has been done.
     * @param   doesn't get any parameters.
     * @return  the symbol of the last operation as a string.
     */
	public String getLastOperationSymbol(){
		return "";
	}
    /**
     * Returns the symbol of the last operation that has been done.
     * @param   "var" the object which we want to derive.
     * @return  new object from the type Constant with value 0.
     */
	public Constant derivative(char varName){
		return new Constant(0);
	}
     /**
      * Returns  the value of the constant in a string form.
      * @param   doesn't get any parameters.
      * @return  the value of the Constant as a String.
      */
		public String toString(){
			return value+"";
	}
	     /**
	      * Returns the value of the constant.
	      * @param   doesn't get any parameters.
	      * @return  the value of the Constant as a double type.
	      */	
		public double evaluate(Assignment assign){
			return value;
	}
	
    /**
     * Indicates whether some other Constant type object is equal to this one in its values
     * @param   other the reference object with which to compare.
     * @return  true if this object is the same as the other argument,and returns false otherwise.
     */
	    public boolean equals(Object other){
		boolean ans=false;
		if (other == null)
			throw new RuntimeException("The constant you want to equlize can't be Null.");
		else if (other instanceof Constant){
				Constant newOther=(Constant) other;
				if (this.value==newOther.value)
					ans=true;
			}
		
		else throw new RuntimeException("The answer is false,because you tried to equalize an " +
				"object that is not from the type Constant.");
		return ans;
		
	}
		/**
		 * Replicating the invoking Constant.
		 * 
		 * @return a replicate of this Constant. The returned Constant has
		 * to be a new object (with a different address than this
		 * object), but equivalent to the this Constant under the 
		 * application of the {@code equals(Object other)} method.
		 */
		public Expression replicate(){
			return new Constant(this.value);
		}

	        
}
